<?php
require_once 'config.php';
$_SESSION['redirect'] = basename(__FILE__);
$page = PGlobal::getAdminLayoutTemplate();
$dondh = new DonDatHang();

$content = new Template(TEMPLATE_DIR . 'admin-dondh.html');

/** Lấy thông tin các hóa đơn */
$data = $dondh->getDonDhNew();
$stt = 0;
if (count($data) == 0) {
    $page['content'] = '<h3>Không có đơn đặt hàng nào</h3>';
} else {
    foreach ($data as $row) {
        $item = new Template(TEMPLATE_DIR . 'admin-dondh-item.html');
        $item->setArray($row);
        $item['giatri'] = PGlobal::toVnd($item['giatri']);
        //$item['ngaydathang'] = substr($item['ngaydathang'], 0, 11);
        $time = new DateTime($item['ngaydathang']);
        $item['ngaydathang'] = $time->format('d-m-Y');
        $item['stt'] = ++$stt;

        $content['admin-dondh-item'] .= $item->render();
    }
    $page['content'] = $content->render();
}

// chitiet-dondh-dialig
$extra = new Template(TEMPLATE_DIR . 'admin-chitietddh-dialog.html');
$page['extra'] = $extra->render();
$dondh->disconnect();

$page->addCss('css/admin-dondh.css');
$page->addJs('jsc/admin-dondh.js');
$page->addJs('jsc/jquery.metadata.js');


echo $page->render();